<title>留言</title>
<link rel="stylesheet" href="/static/public/vendor/select2/select2.css">

<script src="/static/public/vendor/select2/select2.min.js" data-name="select2"></script>
<script src="/static/public/vendor/select2/i18n/zh-CN.min.js" data-deps="select2"></script>
<div class="page-content">
    <div class="panel">
        <div class="panel-body">
            <table class="table table-bordered table-hover dataTable table-striped width-full text-nowrap"
                   id="dataTableExample">
                <thead>
                <tr>
                    <th>标题</th>
                    <th>内容</th>
                    <th>留言者</th>
                    <th>时间</th>
                </tr>
                </thead>
            </table>
        </div>
    </div>
</div>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog" >
        <form class="modal-content"  id='myupload' method="post"   >
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="关闭" ><span aria-hidden="true">×</span></button>
                <h4 class="modal-title" >留言</h4>
            </div>
            <div class="modal-body">

                <div class="row">
                    <div class="col-lg-12 form-group">
                        <input type="text" name="title" class="form-control" id="title" placeholder="留言标题"  required >
                    </div>
                    <div class="col-lg-12 form-group">
                        <textarea class="form-control empty" id="content" name="content" rows="5" placeholder="留言内容" required></textarea>
                    </div>
                    <div class="col-lg-12 form-group">
                        <button type="button" class="btn btn-block btn-success" data-dismiss="modal" onclick="saveMessage()" >发送留言</button>
                    </div>
                </div>


            </div>
        </form>
    </div></div>
<script src="/static/public/vendor/bootstrap-select/bootstrap-select.min.js"></script>
<script type="text/javascript">
    var $table = null;

    function query() {
        $table.ajax.reload();
    }
    function reloadData() {
        $table.ajax.reload();
    }
    function change() {
        $table.ajax.reload();
    }

    $(function () {
        showList();
        // $('#myModal').modal('show');
    });
    function saveMessage() {

        var title=$("#title").val();
        var content=$("#content").val();
        $.ajax({
            url: "#springUrl('/other/questionMessage/save1')",
            data: {"title": title,"content":content},
            type: "POST",
            success: function (data) {
                $table.ajax.reload();
            }
        })
    }
    function showList(){
        $table = $('#dataTableExample').DataTable($.po('dataTable', {
            "processing": true,
            "serverSide": true,
            "ordering": false,
            "columns": [
                {"data": "title"},
                {"data": "content"},
                {"data":"name"},
                {"data":"createTime"}
            ],
            "columnDefs": [{
                "render": function (data, type, row) {
                    return Date.format(new Date(data), "yyyy-MM-dd hh:mm:ss");
                },
                "targets": 3
            }
            ],
            "dom": '<"dt-dom-toolbar">rt<"bottom"pi>',
            "fnServerData": function (sSource, aoData, fnCallback) {
                var params = [
                    {name: "size", value: aoData[4].value}, {
                        name: "current", value: aoData[3].value / aoData[4].value + 1
                    }];
                $.ajax({
                    "dataType": 'json',
                    "type": "post",
                    "data": params,
                    "url": "/other/questionMessage/getDataAll",
                    "success": fnCallback
                });
            }
        }));
        $("div.dt-dom-toolbar").append('<a class="btn btn-success margin-bottom-15 margin-left-15" data-toggle="modal" data-target="#myModal" ><i class="icon wb-edit" aria-hidden="true"></i>留言</a>');
    }
</script>